package test;

import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

public class CatchNodeProcessException implements ActionHandler {

	private static final long serialVersionUID = -5708217284097992021L;


	@Override
	public void execute(ExecutionContext executionContext) throws Exception {
		Throwable e = executionContext.getException();
		this.extractException(e);
		System.out.println("当前是Node1节点捕获的异常，异常的名称为：" + e.getClass().getName() + ", 具体工作的异常消息为：" + e.getMessage());
	}

	
	/**
	 * 异常可能是链状的，该方法的作用是找到根异常
	 * @param e
	 */
	private void extractException(Throwable e) {
		if (e != null) {
			if (e.getCause() != null) {
				this.extractException(e.getCause());
			}
		}
	}
}
